﻿using System;
using System.Collections.Generic;
using SweeperPrototype.Business;
using SweeperPrototype.Business.Fields;
using SweeperPrototype.Business.Keys;

namespace SweeperPrototype.Objects
{

    public partial class PositionSubscription
    {
        public class UniqueKey
        {
            private readonly BookCode m_BookCode;
            private readonly ExposureRIC m_RIC;
            public UniqueKey(BookCode book_code, ExposureRIC ric)
            {
                m_BookCode = book_code;
                m_RIC = ric;
            }

            public UniqueKey(PositionSubscription subscription)
                : this( subscription.BookCode, subscription.RIC ){}

            public BookCode BookCode
            {
                get { return m_BookCode; }
            }

            public ExposureRIC RIC
            {
                get { return m_RIC; }
            }


            public static bool operator ==(UniqueKey lhs, UniqueKey rhs)
            {
                if (ReferenceEquals(null, lhs)) return false;
                if (ReferenceEquals(null, rhs)) return false;

                return lhs.Equals( rhs );
            }

            public static bool operator !=(UniqueKey lhs, UniqueKey rhs)
            {
                return !(lhs == rhs);
            }

            public bool Equals(UniqueKey other)
            {
                if (ReferenceEquals(null, other)) return false;
                if (ReferenceEquals(this, other)) return true;
                return Equals(other.m_BookCode, m_BookCode) && Equals(other.m_RIC, m_RIC);
            }

            public override bool Equals(object obj)
            {
                if (ReferenceEquals(null, obj)) return false;
                if (ReferenceEquals(this, obj)) return true;
                if (obj.GetType() != typeof(UniqueKey)) return false;
                return Equals((UniqueKey)obj);
            }

            public override int GetHashCode()
            {
                unchecked
                {
                    return ((m_BookCode != null ? m_BookCode.GetHashCode() : 0) * 397) ^ (m_RIC != null ? m_RIC.GetHashCode() : 0);
                }
            }
        }
    }
}